# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_realname=QxOrm
pkgbase=mingw-w64-${_realname,,}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname,,}"
         "${MINGW_PACKAGE_PREFIX}-${_realname,,}-docs")
pkgver=1.5.0
pkgrel=1
pkgdesc='A C++ Qt ORM (Object Relational Mapping) and ODM (Object Document Mapper) library (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.qxorm.com/'
msys2_repository_url='https://github.com/QxOrm/QxOrm'
license=('spdx:GPL-3.0-only')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-qt6-base")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-graphviz"
             "${MINGW_PACKAGE_PREFIX}-qt6-tools")
source=("${msys2_repository_url}/archive/${pkgver}/${_realname}-${pkgver}.tar.gz"
        '0001-qxorm-1.4.9-install.patch')
sha256sums=('4e42a15db6a89f08a74f639f805a3c707e3c77b5cab7f66821f07e6a6bc4092e'
            '74b755b0a36c68b39dd291cb324c8bda663d994757908b57b07d7abc8c92c1c6')

prepare() {
    cd "${srcdir}/${_realname}-${pkgver}"

    patch -Np1 -i "${srcdir}"/0001-qxorm-1.4.9-install.patch
}

build() {
    cd "${srcdir}/${_realname}-${pkgver}"/doc/doxygen

    msg2 "Build QxOrm documentation"

    "${MINGW_PREFIX}"/bin/doxygen.exe qxorm.doxygen
}

package_qxorm() {
    cd "${srcdir}/${_realname}-${pkgver}"

    msg2 "Build QxOrm library"

    "${MINGW_PREFIX}"/bin/qmake6.exe CONFIG+=release \
        DEFINES+=_QX_ENABLE_QT_GUI \
        PREFIX="${pkgdir}${MINGW_PREFIX}" \
        QMAKE_CXXFLAGS_RELEASE+="${CXXFLAGS} ${CPPFLAGS} -Wno-deprecated-declarations" \
        QxOrm.pro

    make

    make INSTALL_ROOT="" install

    mkdir -p "${pkgdir}${MINGW_PREFIX}/bin"
    mv "${pkgdir}${MINGW_PREFIX}/lib/"*.dll "${pkgdir}${MINGW_PREFIX}/bin/"

    install -Dm644 license.gpl3.txt "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname,,}/license.gpl3.txt
}

package_qxorm-docs() {
    cd "${srcdir}/${_realname}-${pkgver}"/doc/doxygen

    pkgdesc+=" (documentation)"
    depends=()

    mkdir -p "${pkgdir}${MINGW_PREFIX}"/share/doc/${_realname,,}
    cp -a html "${pkgdir}${MINGW_PREFIX}"/share/doc/${_realname,,}/
}

# template start; name=mingw-w64-splitpkg-wrappers; version=1.0;
# vim: set ft=bash :

# generate wrappers
for _name in "${pkgname[@]}"; do
    _short="package_${_name#${MINGW_PACKAGE_PREFIX}-}"
    _func="$(declare -f "${_short}")"
    eval "${_func/#${_short}/package_${_name}}"
done
# template end;

